package com.tank;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

/**
 * 爆炸类
 *
 * @author LEON
 */
public class Boom {
	private int x;
	private int y;
	private TankClient tankClient;
	private int step = 0;
	private boolean isLive = true;

    /**
     * 获取系统工具,读取系统文件
     */
	private static Toolkit toolkit = Toolkit.getDefaultToolkit();
	private static Image[] boomImages = {
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/0.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/1.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/2.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/3.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/4.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/5.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/6.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/7.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/8.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/9.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/7.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/5.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/3.gif")),
			toolkit.getImage(Boom.class.getClassLoader().getResource("img/1.gif"))
	};

	public Boom(int x, int y, TankClient tankClient) {
		this.x = x;
		this.y = y;
		this.tankClient = tankClient;
	}

	public void drawBoom(Graphics g) {
		if(!isLive) {
			return ;
		}
		if(step == boomImages.length) {
			this.isLive = false;
			this.step = 0;
			this.tankClient.booms.remove(this);
			return ;
		}
		g.drawImage(boomImages[step], x, y, null);
		this.step++;
	}
}
